using System;
using SharedKernel.Domain.Events;

namespace SharedKernel.Domain.Events
{
    /// <summary>
    /// 领域事件基类
    /// </summary>
    public abstract class DomainEvent : IDomainEvent
    {
        /// <summary>
        /// 事件ID
        /// </summary>
        public Guid EventId { get; }

        /// <summary>
        /// 事件发生时间
        /// </summary>
        public DateTime OccurredOn { get; }

        /// <summary>
        /// 构造函数
        /// </summary>
        protected DomainEvent()
        {
            EventId = Guid.NewGuid();
            OccurredOn = DateTime.UtcNow;
        }
    }

    /// <summary>
    /// 泛型领域事件
    /// </summary>
    /// <typeparam name="TEntity">实体类型</typeparam>
    public abstract class DomainEvent<TEntity> : DomainEvent where TEntity : CreateUpdateDeleteEntity<Guid>
    {
        /// <summary>
        /// 关联实体
        /// </summary>
        public TEntity Entity { get; }

        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="entity">关联实体</param>
        protected DomainEvent(TEntity entity)
        {
            Entity = entity;
        }
    }
}